<?php
include_once('config/config.php');

if ($_POST) {
  $name = $_POST['name'];
  $credit = $_POST['credit'];
  $sql = "SELECT name FROM `stu_subject` WHERE `name` = '$name'";
  
  $findData = find($sql);
  if($findData){
    ShowMsg('该学科已存在，请重新输入');
  }

  $data = [
    'name' => $name,
    'credit'=>$credit,
  ];
  $res = add('subject', $data);
  if($res)
  {
    ShowMsg('新增科目成功','subjectlist.php');
  }else{
    ShowMsg('新增科目失败');
  }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <?php include_once('common/meta.php') ?>
</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<style>
  input[type="file"] {
    display: none;
  }

  label[for="avatar"] {
    width: 200px;
  }
</style>

<body>
  <!--<![endif]-->

  <!-- 引用头部 -->
  <?php include_once('common/header.php') ?>

  <!-- 引用菜单 -->
  <?php include_once('common/nav.php') ?>

  <div class="content">
    <div class="header">
      <h1 class="page-title">新增学科</h1>
    </div>
    <ul class="breadcrumb">
      <li><a href="index.php">Home</a> <span class="divider">/</span></li>
      <li><a href="departmentlist.php">SubjectList</a> <span class="divider">/</span></li>
      <li class="active">SubjectAdd</li>
    </ul>

    <div class="container-fluid">
      <div class="row-fluid">

        <div class="btn-toolbar">
          <button class="btn btn-primary" onClick="location='subjectlist.php'"><i class="icon-list"></i>学科列表</button>
          <div class="btn-group">
          </div>
        </div>

        <div class="well">
          <div id="myTabContent" class="tab-content">
            <div class="tab-pane active in" id="home">
              <form method="post" enctype="multipart/form-data">

                <label>科目名称</label>
                <input type="text" name="name" required class="input-xxlarge" placeholder="请输入科目名称">
                <label>学分</label>
                <input type="text" name="credit" required class="input-xxlarge" placeholder="请输入科目学分">
                <label></label>
                <input class="btn btn-primary" type="submit" value="提交" />
              </form>
            </div>
          </div>
        </div>

        <?php include_once('common/footer.php'); ?>

      </div>
    </div>
  </div>
</body>

</html>
<?php include_once('common/script.php'); ?>
<script>

</script>